package org.csu.pm.controller;

import org.csu.pm.annotation.AuthUser;
import org.csu.pm.common.BaseResponse;
import org.csu.pm.model.dto.LoginBody;
import org.csu.pm.model.dto.RegisterBody;
import org.csu.pm.model.dto.UpdatePhoneBody;
import org.csu.pm.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/user")
public class UserController {
    @Autowired
    UserService userService;

    @PostMapping(value = "/login")
    public BaseResponse<?> login(@RequestBody LoginBody loginBody) {
        return userService.login(loginBody);
    }

    @PostMapping(value = "/register")
    public BaseResponse<?> register(@RequestBody RegisterBody loginBody) {
        return userService.register(loginBody);
    }

    @GetMapping(value = "/captcha/{phone}")
    public BaseResponse<?> getCaptcha(@PathVariable("phone") String phone, @AuthUser String userId) {
        return userService.getCaptcha(Long.valueOf(userId), phone);
    }

    @PutMapping(value = "/phone")
    public BaseResponse<?> updatePhone(@RequestBody UpdatePhoneBody updatePhoneBody, @AuthUser String userId) {
        return userService.updatePhone(Long.valueOf(userId), updatePhoneBody);
    }

    @DeleteMapping(value = "/account")
    public BaseResponse<?> deleteAccount(@AuthUser String userId) {
        return userService.deleteAccount(Long.valueOf(userId));
    }

    @GetMapping(value = "/account")
    public BaseResponse<?> getAccountInfo(@AuthUser String userId) {
        return userService.getAccountInfo(Long.valueOf(userId));
    }
}
